import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/parts/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化备件订单'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询备件订单'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询备件订单详情'
});
const signForDesc = formatMessage({
    id: 'api.message.signForDesc',
    defaultMessage: '签收备件订单'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/partShipmentSignFor/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partShipmentSignFors?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/partShipmentSignFors/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
//签收
export const signForApplyReport = (id, data) => request(`${baseUrl}/partShipmentSignFors/${id}`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, signForDesc));
